home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- GlobalData.c
-
- DESCRIPTION
- Contains code that shows a prefered way to manage unique global
- data for different message handler instances. This method
- stores all globals off of the message manager instance context.
- It has the advantage that it will work under any compiler.
- This method is documented in detail in "Inside Macintosh: GX
- Environment & Utilities" starting on page 6-10
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 10/04/95 - David Hayward - Version 1.0.4 modified code so that
- the driver can be build under MPW,
- Metrowerks, and Symantec. In general,
- all that was required to do this was
- to add an inline-assembly jumptable
- and to store all globals off of the
- message manager instance context.
- Also made a few changes so that the
- driver can be rebuilt to support any
- resolution by changing the #defines
- kResolution and kPatStretch in
- "CommonDefines.h"
-
- 06/14/95 - Dave Hersey - Version 1.0.3 to fix a bug in
- CustomBufferingAndIO.c when creating
- high-res PICTs, and to make the size
- of buffers more flexible.
-
- 05/26/95 - Dave Hersey - Version 1.0.2 to add the new 'outp'
- desktop printer resource in NewApp.c.
-
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Begat.
- */
-
-
- #include "GlobalData.h"
-
-
- /* -----------------------------------------------------------------------
-
- GetGlobals returns the DriverGlobals structure
- whose handle is stored in the MessageHandler InstanceContext.
-
- ----------------------------------------------------------------------- */
-
- DriverGlobalsHdl GetGlobals ( void )
- {
- DriverGlobalsHdl dataHandle;
-
- dataHandle = (DriverGlobalsHdl) GetMessageHandlerInstanceContext();
-
- return dataHandle;
- }
-
-
- /* -----------------------------------------------------------------------
-
- CreateAndStoreGlobals is a routine we call to initialize and store a
- handle in the are we allocated at the end of our NewApp.a jump table.
-
- This routine and its counterpart (DisposeGlobals) provide an alternate
- method of handling global data in a driver. The two calls provide a
- method similar to GetMessageHandlerInstanceContext and
- SetMessageHandlerInstanceContext, except that this method can be used
- even if your code didn't receive control via a message override. For
- example, if your code is being executed from a dialog manager
- callback. The standard global data handling routines that are provided
- with QuickDraw GX will only work if your code received control via a
- message override.
-
- ----------------------------------------------------------------------- */
-
- OSErr CreateGlobals ( void )
- {
- OSErr err;
- DriverGlobalsHdl dataHandle;
- DriverGlobals defaultGlobals = { 0x12345678,
- 0, // lineFeeds - accumulated lines feeds
- 0, // pagesImaged - Number of pages imaged.
- 0, // lastYPos - Used by our RasterDatIn override.
- 0, /// curFileRefNum - refNum of current open file.
- 0, // pixMapRowBytes - rowBytes of the pixmap we create.
- {0,0,0,0}, // pixMapBounds - Bounds of the pixmap we create.
- 0, // hRes - Horizontal output resolution.
- 0, // vRes - Vertical output resolution.
- {0,0,"\p"}, // fileLocation - Where to put our files.
- nil // buffer -
- } ;
- /*
- Create a new temporary memory handle, initialize
- it, and store it as the message handler's instance
- context.
- */
-
- dataHandle = (DriverGlobalsHdl) TempNewHandle(sizeof(DriverGlobals),&err);
-
- if (err == noErr)
- {
- (**dataHandle) = defaultGlobals ;
- SetMessageHandlerInstanceContext(dataHandle);
- }
-
- return err;
- }
-
-
- /* -----------------------------------------------------------------------
-
- DisposeGlobals is a routine that disposes of the global data we stored
- in our jump table's data area via CreateAndStoreGlobals.
-
- ----------------------------------------------------------------------- */
-
- void DisposeGlobals ( void )
- {
- DriverGlobalsHdl dataHandle;
-
- /*
- Retrieve the message handler's instance context. If the
- value returned isn't nil, it's a handle that we stored
- earlier. Dispose of the handle and set the instance
- context to nil to "clear" it.
- */
-
- dataHandle = (DriverGlobalsHdl) GetMessageHandlerInstanceContext();
-
- if (dataHandle != nil)
- {
- DisposeHandle( (Handle)dataHandle );
- SetMessageHandlerInstanceContext(nil);
- }
- }
-